﻿using QldtSdh.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QldtSdh.GUI.DaoTao
{
    using DAL.Models;
    using DAL;
    using BLL;
    using QldtSdh.GUI.Utils;
    using QldtSdh.Utils;

    public partial class FormQuanLyNamHocHocKy_TaoLopHocPhan : QldtSdh.GUI.Common.BaseDialog
    {
        private HocKy _HocKyHienTai;
        private bool _PreventCloseThisWindow = false;

        public FormQuanLyNamHocHocKy_TaoLopHocPhan(HocKy hocKy)
        {
            InitializeComponent();
            this._HocKyHienTai = hocKy;
        }

        private void FormQuanLyNamHocHocKy_TaoLopHocPhan_Shown(object sender, EventArgs e)
        {
            _PreventCloseThisWindow = true;
            picProgress.Visible = true;
            BizDaoTao.TaoLopHocPhanTrongKHDT(_HocKyHienTai, DateTime.Now, null,
                (oSender, oE) =>
                {
                    txtLog.Text += oE.UserState.ToString();
                    txtLog.ScrollToLast();
                },
                (oSender, oE) =>
                {
                    if (oE.Cancelled)
                        txtLog.Text += "Đã bị huỷ ngang\r\n";
                    else if (oE.Error != null)
                        txtLog.Text += string.Format("Lỗi: {0}\r\n", oE.Error.ToString());
                    else
                        txtLog.Text += "Đã thực hiện xong.";
                    txtLog.ScrollToLast();
                    _PreventCloseThisWindow = false;
                    picProgress.Visible = false;
                });
        }

        private void FormQuanLyNamHocHocKy_TaoLopHocPhan_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = this._PreventCloseThisWindow;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
